<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.w3.org/1999/xhtml">

<head>
    <th:block th:include="common/common_head :: commonHeader('订单管理')"/>
    <link rel="stylesheet" th:href="@{/static/js/plugins/jquery-layout/jquery.layout-latest.css}">
    <link rel="stylesheet" th:href="@{/static/js/editable/css/bootstrap-editable.css}">
    <!-- <style type="text/css">.table {table-layout:fixed;}</style> -->
</head>

<body class="gray-bg">

<div class="container-div ui-layout-center">
    <div class="row">
        <div class="col-sm-12 search-condition">
            <form id="orderItemForm" th:action="@{/samplePoController/list?poType=SAMPLE}" class="form-inline">
                <div class="select-list">
                    <ul>
                        <li class="col-sm-3" style="width: 33%">
                            <label style="width: 120px">采购凭证号：</label>
                            <input type="text" name="poNo"/>
                        </li>
                        <li class="col-sm-3" style="width: 33%">
                            <label style="width: 120px">订单类型：</label>
                            <select name="poType" sysDict="CGDDLX" emptyFirst="true"></select>
                        </li>
                        <li class="col-sm-3" style="width: 33%">
                            <label style="width: 120px">供应商编码：</label>
                            <input type="text" name="sapCode"/>
                        </li>
                        <li class="col-sm-3" style="width: 33%">
                            <label style="width: 120px">采购组：</label>
                            <select name="purchGroup" sysDict="CGZ" emptyFirst="true"></select>
                        </li>
                        <li class="col-sm-3" style="width: 33%">
                            <label style="width: 120px">物料编码：</label>
                            <input type="text" name="materialCode"/>
                        </li>

                        <li class="col-sm-3" style="width: 33%">
                            <label style="width: 120px">物料描述：</label>
                            <input type="text" name="materialDesc"/>
                        </li>
                        <li class="col-sm-3" style="width: 33.3%">
                            <label style="width: 120px">确认状态：</label>
                            <select id="deliverStatus" name="deliverStatus" emptyFirst="true">
                                <option value=""></option>
                                <option value="0">草稿</option>
                                <option value="-1">已驳回</option>
                                <option value="1">已确认</option>
                                <option value="2">分批发货</option>
                                <option value="3">发货完成</option>
                                <option value="4">已同步SAP</option>
                            </select>
                        </li>
                        <li class="col-sm-3" style="width: 33%">
                            <button id="orderItemSearchBtn" type="button" class="btn btn-primary btn-rounded btn-sm"><i
                                    class="fa fa-search"></i>&nbsp;搜索
                            </button>
                            <button class="btn btn-warning btn-rounded btn-sm" type="reset"><i class="fa fa-eraser"></i>&nbsp;重置
                            </button>
                            <button id="orderItemAdvancedSearch" type="button"
                                    class="btn btn-primary btn-rounded btn-sm" style="display: none"><i
                                    class="fa fa-caret-down"></i>&nbsp;高级搜索
                            </button>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="col-sm-12 select-info order-table">
            <div class="btn-group hidden-xs toolbar" id="orderItemToolBar" role="group">
                <a class="btn btn-outline btn-danger btn-rounded" onclick="toDelete()"
                   shiro:hasPermission="orderItem:delete">
                    <i class="fa fa-trash-o"></i> 删除
                </a>
                <a class="btn btn-outline btn-success btn-rounded" onclick="toEdit()"
                   shiro:hasPermission="orderItem:changer">
                    <i class="fa fa-edit"></i> 变更
                </a>
                <a class="btn btn-outline btn-success btn-rounded" onclick="toUpdate() "
                   shiro:hasPermission="orderItem:confirm">
                    <i class="fa fa-star"></i> 确认
                </a>
                <a class="btn btn-outline btn-success btn-rounded" onclick="toRemove()"
                   shiro:hasPermission="orderItem:cancel">
                    <i class="fa fa-star"></i> 驳回
                </a>
                <a class="btn btn-outline btn-success btn-rounded" onclick="addReplyDate()"
                   shiro:hasPermission="orderItem:replyDate">
                    <i class="fa fa-star"></i> 回复交期
                </a>
                <a class="btn btn-outline btn-success btn-rounded" onclick="toSendSap()"
                   shiro:hasPermission="orderItem:sendSap">
                    <i class="fa fa-star"></i> 同步SAP
                </a>
                <a class="btn btn-outline btn-success btn-rounded" onclick="toSend()"
                   shiro:hasPermission="orderItem:fahuo">
                    <i class="fa fa-star"></i> 发货
                </a>
                <a class="btn btn-outline btn-success btn-rounded" id="sendid" data-toggle='modal' data-target=''
                   shiro:hasPermission="orderItem:fpfahuo" onclick="toSendBatche()">
                    <i class="fa fa-plus"></i> 分批发货
                </a>
                <!--<a class="btn btn-outline btn-success btn-rounded" onclick="showUploadDialog()">
                    <i class="fa fa-upload"></i> 上传报告
                </a>
                <a class="btn btn-outline btn-success btn-rounded" onclick="showdownloadDialog()">
                    <i class="fa fa-download"></i> 下载报告
                </a>
                <a class="btn btn-outline btn-success btn-rounded" onclick="showReportDetailDialog()">
                    <i class="fa fa-search"></i> 查看报告
                </a>-->
                <a class="btn btn-outline btn-success btn-rounded" onclick="tryOut()">
                    <i class="fa fa-file-excel-o"></i> 试用报告
                </a>

            </div>
            <table id="orderItem" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>

<!--上传报告-->
<!--<div id="uploadModal" style="display: none">
    <div class="modal-body">
        <form id="uploadForm" enctype="multipart/form-data">
            <div style="margin-top:20px">
                <label><b>上传类型：</b></label>
                <label id="uploadType">
                </label>
                <label style="color: red">*</label>
            </div>
            <div style="margin-top:20px"><label><b>选择文件：</b></label><input type="file" name="reportFile" id="reportFile"
                                                                           style="display:inline"> <label
                    style="color: red">*</label></div>
            <div style="margin-top:20px"><label><b>备注：</b></label><textarea id="remark" name="remark"
                                                                            style="width:80%; height:150px;"></textarea>
            </div>
        </form>
    </div>
    <div class="modal-footer">
        <button type="button" class="btn btn-default" onclick='closeDialog()'>关闭</button>
        <button type="button" class="btn btn-primary" onclick='uploadReport()'>确定</button>
    </div>
</div>

&lt;!&ndash;下载报告&ndash;&gt;
<div id="downloadModal" style="display: none">
    <div class="modal-body">
        <form id="downloadForm" method="post">
            <div class="checkbox" id="downloadCheckbox">
            </div>
        </form>
    </div>
    <div class="modal-footer">
        <button type="button" class="btn btn-default" onclick='closeDialog()'>关闭</button>
        <button type="button" class="btn btn-primary" onclick='downloadReport()'>确定</button>
    </div>
</div>

&lt;!&ndash;查看报告&ndash;&gt;
<div id="reportDetailModal" style="display: none">
    <div class="modal-body">
        <table class="table" id="reportDetailTable">
            <thead>
            <tr>
                <th data-field="type">报告类型</th>
                <th data-field="isUpload">是否上传</th>
                <th data-field="time">上传时间</th>
                <th data-field="remark">备注</th>
            </tr>
            </thead>
        </table>
    </div>
    <div class="modal-footer">
        <button type="button" class="btn btn-default" onclick='closeDialog()'>关闭</button>
    </div>
</div>-->

<!--引入公共js-->
<div th:include="common/onload_js :: onloadJS"></div>
<script type="text/javascript" th:src="@{/static/js/plugins/jquery-layout/jquery.layout-latest.js}"></script>

<!-- Page-Level Scripts -->
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document" style="width:70%">
        <div class="modal-content" style="height:700px">
            <form id="orderForm" th:action="@{/orderItem/list}" class="form-inline">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <h4 class="modal-title" id="myModalLabel">发货信息明细</h4>
                </div>
                <input type="hidden" id="ids" name="ids" value=""/>
                <div class="modal-body" style="height:90%;width:90%;overflow:auto">
                    <div style="height: 30px">
                        <ul>
                            <li class="col-sm-3" style="width: 33.3%">
                                <label style="width: 90px">采购凭证号：</label>
                                <input type="text" id="poNo" name="poNo"/>
                            </li>
                            <li class="col-sm-3" style="width: 33.3%">
                                <label style="width: 70px">订单类型：</label>
                                <select id="poType" name="poType" sysDict="CGDDLX" emptyFirst="true"></select>
                            </li>
                            <li class="col-sm-3" style="width: 33.3%">
                                <label style="width: 120px">供应商编码：</label>
                                <input type="text" id="sapCode" name="sapCode"/>
                            </li>
                            <li class="col-sm-3" style="width: 33.3%">
                                <label style="width: 70px">采购组：</label>
                                <select id="purchGroup" name="purchGroup" sysDict="CGZ" emptyFirst="true"
                                        style="width: 55%"></select>
                            </li>
                            <li class="col-sm-3" style="width: 33.3%">
                                <label style="width: 120px">物料编码：</label>
                                <input type="text" id="materialCode" name="materialCode"/>
                            </li>
                            <li class="col-sm-3" style="width: 33.3%">
                                <button id="orderSearchBtn" type="button" class="btn btn-primary btn-rounded btn-sm"><i
                                        class="fa fa-search"></i>&nbsp;搜索
                                </button>
                                <button class="btn btn-warning btn-rounded btn-sm" type="reset"><i
                                        class="fa fa-eraser"></i>&nbsp;重置
                                </button>
                                <button id="orderAdvancedSearch" type="button"
                                        class="btn btn-primary btn-rounded btn-sm" style="display: none"><i
                                        class="fa fa-caret-down"></i>&nbsp;高级搜索
                                </button>
                            </li>
                        </ul>
                    </div>
                    <table id="order" data-mobile-responsive="true"></table>
                </div>
            </form>
            <div class="modal-footer">
                <button id="close" type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick='save()'>确定</button>
            </div>
        </div>
    </div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->

<!--供应商回复交期-->
<div id="replyDateModal" style="display: none">
    <div class="modal-body" style="margin-bottom: 70px;padding-top: 50px;">
        <label>回复交期：</label>
        <input id="replyDateInput" style="display: inline;width: 200px;" type="text" class="form-control"
               autocomplete="off">
        <label style="color: red">*</label>
    </div>
    <div class="modal-footer">
        <button type="button" class="btn btn-default" onclick='closeDialog()'>关闭</button>
        <button type="button" class="btn btn-primary" onclick='updateReplyDate()'>确定</button>
    </div>
</div>

<script type="text/javascript">
    //面向对象
    var searcherBS = Searcher.createBS('#orderItem',
        [
            {checkbox: true},
            {title: '采购凭证号', field: 'poNo'},
            {title: '订单行项目号', field: 'itemNo'},
            {
                title: '订单确认状态', field: 'itemStatus',
                formatter: function (value, row, index) {
                    if (value == 0) {
                        return "草稿";
                    } else if (value == -1) {
                        return "订单已经取消";
                    } else if (value == 1) {
                        return "订单已确认";
                    } else if (value == 2) {
                        return "分批发货";
                    } else if (value == 3) {
                        return "订单发货完毕";
                    } else if (value == 4) {
                        return "SAP同步成功";
                    }
                }
            },
            {title: '物料编码', field: 'materialCode'},
            {title: '物料描述', field: 'materialDesc'},
            {title: '工厂', field: 'factory'},
            {title: '库存地点', field: 'storage'},
            /* {title: '试用次数', field: 'reason'},*/
            {title: '物料组', field: 'materialGroup'},
            {title: '需求者姓名', field: 'requester'},
            {title: '采购订单数量', field: 'poCount'},
            {title: '待发货的数量', field: 'backOrders'},
            {title: '采购订单的计量单位', field: 'poUnit'},
            {title: '含税单价', field: 'poPrice'},
            {title: '税码', field: 'taxCode'},
            {title: '订单总价值', field: 'totalPrice'},
            /* {title: '发票收据标识', field: 'receiveFlag'},*/
            {title: '采购申请编号', field: 'prNo'},
            {title: '采购申请项目编号', field: 'prItemNo'},
            {title: '需求日期', field: 'deliveryDate'},
            {title: '供应商回复交期', field: 'replyDate'},
            {title: '成本中心', field: 'costCenter'},
            {title: '备注', field: 'remark'},
            {title: '公司代码', field: 'companyCode'},
            {title: '采购组', field: 'purchGroup'},
            {title: '采购组织', field: 'purchOrg'},
            {title: '付款条件代码', field: 'payCondition'},
            {title: '货币码', field: 'currencyCode'},
            {title: '供应商', field: 'sapCode'},
            {title: '供应商名称', field: 'vendorName'},
            {title: '创建日期', field: 'creationDate'},
        ]
    );

    $(function () {
        // 初始化时间插件
        laydate.render({elem: '#replyDateInput'});
    });

    /**
     * 查询数据
     */
    function refresh() {
        searcherBS.refresh();
    }

    /*
    *初始化所有字典数据
    */
    $(function () {
        initDictDataSel();
    });

    /**
     * 编辑
     */
    function toEdit() {
        var rowDatas = searcherBS.getSelectedRows("poNo");
        if (rowDatas.length != 1) {
            Dialog.errorMsg("请选择一行进行编辑!");
            return;
        }
        var selectItems = searcherBS.getRawData();
        for (var item in selectItems) {
            if (selectItems[item].itemStatus != '-1' && selectItems[item].itemStatus != '0') {
                Dialog.errorMsg("订单已确认过，不可变更！");
                return;
            }
        }
        var index = Dialog.openUrl("更改订单信息", ctxPath + '/orderHead/toEdit/' + rowDatas,
            {
                area: ['900px', '700px'],
                maxmin: true,
                end: function () {
                }
            });
        layer.full(index);
    }

    /**
     * @Description: 样品订单增加
     */
    function toAdd() {
        var index = Dialog.openUrl("更改订单信息", ctxPath + '/orderHead/toEdit/' + rowDatas,
            {
                area: ['900px', '700px'],
                maxmin: true,
                end: function () {
                }
            });
        layer.full(index);
    }

    /**
     * 确认订单
     */
    function toUpdate() {
        var rowDatas = searcherBS.getRawData();
        if (rowDatas.length < 1) {
            Dialog.errorMsg("请选择一行进行确认");
            return;
        }
        for (var item in rowDatas) {
            if (rowDatas[item].itemStatus == '1') {
                Dialog.errorMsg("订单已处于确认状态！");
                return;
            } else if (rowDatas[item].itemStatus == '2' || rowDatas[item].itemStatus == '3') {
                Dialog.errorMsg("订单已发货，不能确认！");
                return;
            } else if (rowDatas[item].itemStatus == '4') {
                Dialog.errorMsg("订单已同步SAP，不能确认！");
                return;
            }
        }
        //field:"pkId"
        var poItemIds = searcherBS.getSelectedRows("poItemId");
        Page.ajaxPOST(ctxPath + "/orderItem/toupdate", {"ids": poItemIds}, function () {
            Dialog.msg("操作成功", function () {
                searcherBS.refresh();
            });
        });
    }


    /**
     *供应商回复交期
     */
    function addReplyDate() {
        var rowDatas = searcherBS.getRawData();
        if (rowDatas.length < 1) {
            Dialog.errorMsg("请选择一行添加回复交期！");
            return;
        }
        for (var item in rowDatas) {
            if (rowDatas[item].itemStatus == '2') {
                Dialog.errorMsg("订单已发货，不能添加回复交期！");
                return;
            } else if (rowDatas[item].itemStatus == '3') {
                Dialog.errorMsg("订单已发货完毕，不能添加回复交期！");
                return;
            }
        }
        $("#replyDateInput").val('');
        Dialog.open("添加回复交期", $("#replyDateModal"), {area: ['500px', '300px']});
    }

    /**
     *供应商回复交期更新数据
     */
    function updateReplyDate() {
        var poItemIds = searcherBS.getSelectedRows("poItemId");
        var replyDate = $("#replyDateInput").val();
        if (!replyDate) {
            Dialog.errorMsg("请选择回复交期！");
            return;
        }
        layer.load(1, {shade: [0.3, '#393D49']});
        Page.ajaxPOST(ctxPath + "/orderItem/updateReplyDate", {
            "ids": poItemIds,
            "replyDate": replyDate
        }, function () {
            Dialog.msg("操作成功", function () {
                searcherBS.refresh();
            });
            layer.closeAll();
        });
    }

    /**
     * 驳回
     */
    function toRemove() {
        var rowDatas = searcherBS.getRawData();
        if (rowDatas.length < 1) {
            Dialog.errorMsg("请选择一行进行驳回！");
            return;
        }
        for (var item in rowDatas) {
            if (rowDatas[item].itemStatus == '2' || rowDatas[item].itemStatus == '3' || rowDatas[item].itemStatus == '4') {
                Dialog.errorMsg("订单已发货或同步SAP后不可驳回！");
                return;
            } else if (rowDatas[item].itemStatus == '-1') {
                Dialog.errorMsg("订单已处于驳回状态！");
                return;
            }
        }
        //field:"pkId"
        var poItemIds = searcherBS.getSelectedRows("poItemId");
        Page.ajaxPOST(ctxPath + "/orderItem/toRemove", {"ids": poItemIds}, function () {
            Dialog.msg("操作成功", function () {
                searcherBS.refresh();
            });
        });
    }

    /**
     发货
     */
    function toSend() {
        var rowDatas = searcherBS.getSelectedRows("poItemId");
        var rowData = $("#orderItem").bootstrapTable('getSelections');
        var goodsStatus;
        if (rowData.length < 1) {
            Dialog.errorMsg("请至少选择一行进行编辑");
            return;
        }
        for (var i = 0; i < rowData.length; i++) {
            goodsStatus = rowData[i].itemStatus;
        }
        if (goodsStatus == 4) {
            Page.ajaxPOST(ctxPath + "/orderItem/toSend", {"ids": rowDatas}, function () {
                Dialog.msg("操作成功", function () {
                    searcherBS.refresh();
                });
            });
        } else {
            Dialog.errorMsg("订单没有同步SAP!");
            document.getElementById("close").click();

        }
    }

    /**
     分批发货
     */
    //方法一
    /* document.getElementById("importJsp").setAttribute("src","#");
     //iframe标签的src属性值已更改为"#"
     console.log(document.getElementById("importJsp").getAttribute("src"));
     //方法二
     document.getElementById("importJsp").attributes["src"].value="#";
     //iframe标签的src属性值已更改为"#"
     console.log(document.getElementById("importJsp").getAttribute("src"));*/
    var searcherbs;

    function toSendBatche() {
        $("#order").find("tbody").remove();
        //得到选中的行项目id
        var rowDatas = searcherBS.getSelectedRows("poItemId");
        var rowData = $("#orderItem").bootstrapTable('getSelections');
        var goodsStatus;
        if (rowDatas.length < 1) {
            Dialog.errorMsg("请至少选择一行进行编辑");
            return;
        }
        for (var i = 0; i < rowData.length; i++) {
            goodsStatus = rowData[i].itemStatus;
            if (goodsStatus == 1 || goodsStatus == 2) {
                document.getElementById("sendid").setAttribute("data-target", "#myModal");
                $("#ids").val(rowDatas);
                searcherbs = Searcher.createBS('#order',
                    [
                        //{checkbox: true },
                        {title: '物料编码', field: 'materialCode', clickToSelect: false},
                        {title: '物料描述', field: 'materialDesc', clickToSelect: false},
                        {title: '采购凭证号', field: 'poNo', clickToSelect: false},
                        {title: '订单确认状态', field: 'itemStatus', clickToSelect: false},
                        {title: '行项目号', field: 'itemNo', clickToSelect: false},
                        {title: '采购订单数量', field: 'poCount', clickToSelect: false},
                        {title: '已发货数量', field: 'shippedQty', clickToSelect: false},
                        //editable:true,//开启编辑模式
                        {
                            title: '本次发货数量', field: 'dueOut',
                            formatter: function (value, row, index, field) {
                                return '<input oninput="OnInput (event)" onchange="change(' + this + ')" contenteditable="true" type="number" name="dueOut" size="10" id="ipt' + row.poItemId + '" min="0" max="' + (row.poCount - row.shippedQty) + '" value="' + (row.poCount - row.shippedQty) + '">';
                            },
                            clickToSelect: false //是否启用点击选中行
                        }
                    ], {
                        pageList: [10], pageSize: 10, showColumns: false,
                        onCheck: function (row) {
                        },
                        onPostBody: function () {
                        }
                    }
                );
                searcherbs.refresh();

            } else {
                document.getElementById("sendid").setAttribute("data-target", "");
                Dialog.errorMsg("订单没有确认");
                return;
            }
        }
    }

    /**
     * 保存
     */
    function save() {
        var myMap = {};
        //得到选中的行
        var ss = searcherbs.getSelectedRows("poItemId");
        var ss = $("#ids").val().split(",");
        for (var i = 0; i < ss.length; i++) {
            myMap[ss[i]] = $("#ipt" + ss[i]).val();
        }
        var json = {"ids": myMap};
        Page.ajaxPOST(ctxPath + "/orderItem/save", JSON.stringify(json), function () {
            Dialog.msg("操作成功", function () {
                searcherBS.refresh();
            });
        }, {contentType: "application/json",}, {"loadingMsg": "正在往服务器提交数据……"});
        $('#myModal').modal('hide');
    }

    /**
     * 传输SAP
     */
    function toSendSap() {
        var rowData = $("#orderItem").bootstrapTable('getSelections');
        var goodsStatus;
        if (rowData.length < 1) {
            Dialog.errorMsg("请至少选择一行进行编辑");
            return;
        }
        for (var i = 0; i < rowData.length; i++) {
            goodsStatus = rowData[i].itemStatus;
        }
        if (goodsStatus == 1) {
            var rowDatas = searcherBS.getSelectedRows("poItemId");
            Page.ajaxPOST(ctxPath + "/orderItem/toSendSap", {"ids": rowDatas}, function () {
                Dialog.msg("同步成功!", function () {
                    searcherBS.refresh();
                });
            }, {"loadingMsg": "正在往服务器提交数据……"});
        } else if (goodsStatus == 4) {
            Dialog.errorMsg("该订单已经同步SAP!");
        } else {
            Dialog.errorMsg("订单没有确认!");
        }
    }

    // Firefox, Google Chrome, Opera, Safari, Internet Explorer from version 9
    // function OnInput (event) {
    // alert ("The new content: " + event.target.value);
    // }

    function change(obj) {
        var dueOut = obj.poCount - obj.shippedQty;
        var text = event.target.value;
        alert("原值：" + dueOut);
        alert("新值：" + text);
    }

    // Internet Explorer
    // function OnPropChanged (event) {
    //if (event.propertyName.toLowerCase () == "value") {
    //  alert ("The new content: " + event.srcElement.value);
    //  }
    // }


    /**
     *上传报告
     */
    /*function showUploadDialog() {
        var rowData = searcherBS.getRawData();
        if (rowData.length != 1) {
            Dialog.errorMsg("请选择一行进行上传！");
            return;
        }
        rowData = rowData[0];
        //报告均已上传
        if (rowData.deliverFirstFile && rowData.deliverSecondFile && rowData.deliverThirdFile) {
            Dialog.errorMsg("所有报告均已上传！");
            return;
        }
        //上传报告窗口
        Dialog.open('文件上传', $("#uploadModal"), {area: ['500px', '450px']});
        //动态添加选项
        var node = '';
        var nodeValue = '';
        if (!rowData.deliverFirstFile) {
            node += "第一次出货检验报告";
            nodeValue = 'deliverFirstFile';
        } else if (!rowData.deliverSecondFile) {
            node += "第二次出货检验报告";
            nodeValue = 'deliverSecondFile';
        } else if (!rowData.deliverThirdFile) {
            node += "第三次出货检验报告";
            nodeValue = 'deliverThirdFile';
        }
        $("#uploadType").text(node);
        $("#uploadType").val(nodeValue);
    }*/

    //上传文件取消
    /* function closeDialog() {
         layer.closeAll();
     }

     function uploadReport() {
         var uploadType = $("#uploadType").val();
         var reportFile = $("#reportFile").val();
         if (!reportFile) {
             Dialog.errorMsg("请上传文件！");
             return;
         }
         var rowData = searcherBS.getRawData()[0];
         var formData = new FormData($('#uploadForm')[0]);
         formData.append("poItemId", rowData.poItemId);
         formData.append("uploadType", uploadType);
         uploadId = rowData.uploadId;
         if (uploadId == undefined || uploadId == null) {
             uploadId = '';
         }
         formData.append("uploadId", uploadId);
         layer.load(1, {shade: [0.3, '#393D49']});
         $.ajax({
             url: ctxPath + "/orderItem/uploadFile",
             type: 'POST',
             data: formData, // 上传formdata封装的数据包
             dataType: 'JSON',
             cache: false, // 不缓存
             processData: false, // jQuery不要去处理发送的数据
             contentType: false, // jQuery不要去设置Content-Type请求头
             success: function (data) {
                 layer.closeAll();
                 if (data.result) {
                     Dialog.msg("操作成功!", function () {
                     });
                 } else {
                     Dialog.msg("操作失败，请重新上传!", function () {
                     });
                 }
                 searcherBS.refresh();
                 //清除表单内容
                 $("#reportFile").val("");
                 $("#remark").val("");
             }
         });
     }*/

    /* /!**
      *下载报告
      *!/
     function showdownloadDialog() {
         var rowData = searcherBS.getRawData();
         if (rowData.length == 0) {
             Dialog.errorMsg("请选择一行进行下载！");
             return;
         }
         rowData = rowData[0];
         if (!rowData.deliverFirstFile && !rowData.reportSecondFile && !rowData.deliverThirdFile) {
             Dialog.errorMsg("没有报告上传！");
             return;
         }
         //文件下载路径
         var node = '';
         if (rowData.deliverFirstFile) {
             node += "<div style='margin:20px;font-size:1.3em'><label><input type='checkbox' style='margin-top: 6px;' name='files' value='" + rowData.deliverFirstFile + "'>第一次出货检验报告</label></div>";
         }
         if (rowData.deliverSecondFile) {
             node += "<div style='margin:20px;font-size:1.3em'><label><input type='checkbox' style='margin-top: 6px;' name='files' value='" + rowData.deliverSecondFile + "'>第二次出货检验报告</label></div>";
         }
         if (rowData.deliverThirdFile) {
             node += "<div style='margin:20px;font-size:1.3em'><label><input type='checkbox' style='margin-top: 6px;' name='files' value='" + rowData.deliverThirdFile + "'>第三次出货检验报告</label></div>";
         }
         $("#downloadCheckbox").html(node);
         //下载报告窗口
         Dialog.open("下载文件", $("#downloadModal"), {area: ['400px', '500px']});
     }*/

    /*function downloadReport() {
        $("#downloadForm").attr("action", ctxPath + "/orderItem/downloadFile");

        var checkReports = $("input[name='files']:checked");
        var len = checkReports.length;
        if (len == 0) {
            Dialog.errorMsg("请选择要下载的试用报告！");
            return;
        }
        $("#downloadForm").submit();
        layer.closeAll();
    }
*/
    //删除订单
    function toDelete() {
        var rowData = searcherBS.getRawData();
        if (rowData.length == 0) {
            Dialog.errorMsg("请选择要删除的定单！");
            return;
        }
        var itemIds = [];
        for (var i in rowData) {
            if (rowData[i].itemStatus != 0 && rowData[i].itemStatus != -1) {
                Dialog.errorMsg("非草稿状态定单不可删除！");
                return;
            }
            itemIds.push(rowData[i].poItemId);
        }
        layer.load(1, {shade: [0.3, '#393D49']});
        $.ajax({
            type: "get",
            url: ctxPath + "/orderItem/deleteOrders?type=SAMPLE&itemIds=" + itemIds,
            contentType: "application/json;charset=UTF-8",//必须
            cache: true,
            error: function (data) {
                Dialog.msg("删除失败，请重试！");
                closeDialog();
                layer.closeAll();
            },
            success: function (data) {
                layer.closeAll();
                if (data.code == 500) {
                    Dialog.errorMsg(data.msg, null, {time: 3000});
                } else {
                    Dialog.msg(data.msg);
                }
                searcherBS.refresh();
            }
        });
    }

    /**
     *查看报告
     */
    /* function showReportDetailDialog() {
         var rowData = searcherBS.getRawData();
         if (rowData.length == 0) {
             Dialog.errorMsg("请选择一行进行查看！");
             return;
         }
         rowData = rowData[0];
         var tableData = [];
         var deliverFirstFile = {type: '第一次出货检验报告', isUpload: "否", time: '', remark: ''};
         var deliverSecondFile = {type: '第二次出货检验报告', isUpload: "否", time: '', remark: ''};
         var deliverThirdFile = {type: '第三次出货检验报告', isUpload: "否", time: '', remark: ''};
         //第一次出货检验报告
         if (rowData.deliverFirstFile) {
             deliverFirstFile.isUpload = "是";
             deliverFirstFile.time = rowData.deliverFirstFile.substring(rowData.deliverFirstFile.lastIndexOf("_") + 1, rowData.deliverFirstFile.lastIndexOf(".")).replace(/~/g, ':');
         }
         if (rowData.deliverFirstRemark) {
             deliverFirstFile.remark = rowData.deliverFirstRemark;
         }
         //第二次出货检验报告
         if (rowData.deliverSecondFile) {
             deliverSecondFile.isUpload = "是";
             deliverSecondFile.time = rowData.deliverSecondFile.substring(rowData.deliverSecondFile.lastIndexOf("_") + 1, rowData.deliverSecondFile.lastIndexOf(".")).replace(/~/g, ':');
         }
         if (rowData.deliverSecondRemark) {
             deliverSecondFile.remark = rowData.deliverSecondRemark;
         }
         //第三次出货检验报告
         if (rowData.deliverThirdFile) {
             deliverThirdFile.isUpload = "是";
             deliverThirdFile.time = rowData.deliverThirdFile.substring(rowData.deliverThirdFile.lastIndexOf("_") + 1, rowData.deliverThirdFile.lastIndexOf(".")).replace(/~/g, ':');
         }
         if (rowData.deliverThirdRemark) {
             deliverThirdFile.remark = rowData.deliverThirdRemark;
         }
         tableData[0] = deliverFirstFile;
         tableData[1] = deliverSecondFile;
         tableData[2] = deliverThirdFile;
         //查看报告窗口
         Dialog.open("查看报告", $("#reportDetailModal"), {area: ['800px', '480px']});
         $("#reportDetailTable").bootstrapTable('destroy');
         $('#reportDetailTable').bootstrapTable({data: tableData});
     }*/

    /**
     * 试用报告
     */

    function tryOut() {
        var pkIds = searcherBS.getSelectedRows("poItemId");
        if (pkIds.length != 1) {
            Dialog.errorMsg("请选择一行进行操作！");
            return;
        }
        var itemStatus = searcherBS.getSelectedRows("itemStatus");
        if (itemStatus != 4) {
            Dialog.errorMsg("该订单还不能形成试用报告");
            return;
        }
        var index = Dialog.openUrl("试用报告", ctxPath + '/samplePoController/tryOut?pkId=' + pkIds,
            {
                area: ['900px', '700px'],
                maxmin: true,
                end: function () {
                }
            });
        layer.full(index);
    }

</script>
</body>
</html>
